﻿#region copyright
/*
 * Author: Jan Vilimek: jan (at) vilimek (dot) cz
 * If you use any code from this program/library, please include above line
 * 
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace pdb2mobiGUI
{
	class PDBRecord
	{
		public UInt32 offset;
		public byte recordAttribute;
		/// <summary>
		/// ONLY 3 BYTES!
		/// </summary>
		public UInt32 uniqueID;

		public PDBRecord()
		{
			offset = 0;
			recordAttribute = 0x40;
			uniqueID = 0;
		}

		public bool Read(BinaryReader br)
		{

			var tSize = 8;
			var buff = br.ReadBytes(tSize);
			if (buff.Length < tSize)
				return false;	//wrong file?
			this.offset = Utils.ConvertBigEndianUInt32(buff, 0);
			this.recordAttribute = buff[4];
			this.uniqueID = Utils.ConvertBigEndianUInt32(buff, 5);
			if (this.offset <= 0)
				return false;
			//br.BaseStream.Seek(this.offset, SeekOrigin.Begin);

			return true;
		}

		public int? dataLength = null;

		public byte[] Data;
		public string DataString
		{
			get
			{
				return Encoding.GetEncoding(PDBHeader.CodePage).GetString(Data);
			}
		}
	}
}
